import {defineStore} from "pinia";
import {computed, ref} from "vue";

export const useUserStore = defineStore('user', () => {
    const user = ref(null);
    //返回user
    const userInfo = computed(() => user.value);

    //更新token
    function updateUser(u) {
        user.value = u;
    }

    //重置token
    function $reset() {
        user.value = null;
    }

    return {user, userInfo, updateUser, $reset};
}, {
    persist: {
        key: 'user',
        storage: sessionStorage,
    }
});